// 实体
import * as $iframe from '@/utils/report/iframe/iframe'
export const entityScript = {
  init: function(scriptJson) {
    // 判断是否存在dtms
    if (!Object.prototype.hasOwnProperty.call(scriptJson, 'doms')) {
      scriptJson.doms = {}
    }
    if (!Object.prototype.hasOwnProperty.call(scriptJson['doms'], 'machineOrd')) {
      scriptJson.doms.machineOrd = entityScript
    }
  },
  isinfoPop(code) {
    return false
  },
  infoButtonClick: function(vueObject, data, btnEvent) {
    return false
  },
  // 按钮点击
  buttonClick: function(vueObject, row, btnEvent) {
    if (btnEvent === 'details') {
      this.details(vueObject, row)
      return true
    } else if (btnEvent === 'closeIframe') {
      this.closeIframe(vueObject, row)
      return true
    } else {
      return false
    }
  },
  details: function name(vueObject, row) {
    if (!row) {
      vueObject.$message({
        type: 'warning',
        message: '请选择需要修改的行!'
      })
    } else {
      const urlCode = '001003'
      const params = {
        // show: true,
        title: '命令工单',
        code: 'commandorderinfo'
      }
      vueObject.iframes.push(params)

      const childIframeUrl = window.location.origin + '/#' + '/report/commandorderinfo'
      vueObject.$nextTick(() => {
        const orderDom = document.querySelectorAll('#iframe')[[document.querySelectorAll('#iframe').length - 1]]
        const data = {
          code: 'commandorderinfo',
          iframeUrl: childIframeUrl,
          params: {
            urlCode: urlCode,
            code: row.code
          }
        }
        $iframe.creatIframe(orderDom, data, vueObject.iframeDom, vueObject)
      })

      // const backUrl = vueObject.$route.path
      // vueObject.$store.commit('report/SET_REPORT_ORDER_code', row.code)
      // vueObject.$store.commit('report/SET_REPORT_ORDER_urlCode', '001003')
      // vueObject.$router.push({
      //   name: 'report/commandorderinfo',
      //   params: {
      //     code: row.code,
      //     urlCode: '001003',
      //     backUrl: backUrl
      //   }
      // })
    }
  },
  closeIframe: function(vueObject, code) {
    $iframe.closeIframe(code, vueObject.iframes, vueObject.iframeDom)
  },
  // 表头样式初始化
  onInfoHeadFrameInit: function(vueObject, headFrameData) {
    //
  },
  // 表身样式初始化
  onInfoBodyFrameInit: function(vueObject, bodyFrameData) {
    //
  },
  // 表身新建行
  onAddBodyRow: function(vueObject, bodyName, itemData) {
    //
    //
  },
  // 表头改变事件
  onHeadChange: function(vueObject, data, fieldName, oldValue, newValue) {
    //
    //
    //
  },
  // 表身改变事件
  onBodyChange: function(vueObject, data, bodyName, lineNum, fieldName, oldValue, newValue) {
    //
    //
    //
    //
    //
  }
}
